import { Exclude, Expose } from 'class-transformer';
import { MeetingRoom } from '../../meeting-room/entities/meeting-room.entity';
import { UserEntity } from '../../user/entities/user.entity';
import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

export enum BookingStatus {
  SUCCESS = 'success',
  PENDING = 'pending',
  REJECTED = 'rejected',
  CANCELLED = 'cancelled',
}

@Entity('booking')
@Exclude()
export class Booking {
  @Expose()
  @PrimaryGeneratedColumn({ comment: '主键ID' })
  id: number;

  @Expose()
  @Column({ comment: '预约开始时间' })
  startTime: Date;

  @Expose()
  @Column({ comment: '预约结束时间' })
  endTime: Date;

  @Expose()
  @Column({
    comment: '状态',
    type: 'enum',
    enum: BookingStatus,
    default: BookingStatus.PENDING,
  })
  status: BookingStatus;

  @Expose({ groups: ['booking-detail'] })
  @Column({ comment: '备注', length: 100, default: '' })
  note?: string;

  @Expose({ groups: ['booking-detail'] })
  @ManyToOne(() => UserEntity)
  user: UserEntity;

  @Expose({ groups: ['booking-detail'] })
  @ManyToOne(() => MeetingRoom, (room) => room.bookings)
  room: MeetingRoom;

  @CreateDateColumn({ comment: '创建时间' })
  createTime: Date;

  @UpdateDateColumn({ comment: '更新时间' })
  updateTime: Date;
}
